
*cap cd "/Users/*PATH*/

log using "Replication.log", replace
************************+
***************************
**ANALYSES
***************************
****************

use "Data_Officers_replication.dta", clear



*******************+
* MAIN REGRESSIONS
***********************


*1 MODELS WITHOUT COVARIATES

logit  vote_2016 treatment, 
margins, dydx(   treatment) post
estimates store s1


logit  vote_april  treatment, 
margins, dydx( treatment) post
estimates store s2


logit   vote_may  treatment, 
margins, dydx( treatment) post
estimates store s3



logit   vote_nov treatment, 
margins, dydx(   treatment) post
estimates store s4

coefplot (s1 , label( "Turnout 2016 (Placebo)")) ( s2, label( "Turnout April 2019")) ///
 ( s3, label( "Turnout May 2019 (Short-term effect)")) ( s4, label("Turnout November 2019 (Long-term effect)")) ///
 , keep ( treatment) vertical yline(0) ylabel(-0.04(.04).2)  xlabel("") title ("Models without covariates") legend(position(6))  ytitle("ATE")  level(95)

 graph copy g1
 
*2 MODELS WITH COVARIATES

logit  vote_2016  treatment female age low_education high_educat i.employmentstatus 

margins, dydx(   treatment) post
estimates store s1

logit  vote_april  treatment female age low_education high_educat i.employmentstatus 
margins, dydx(   treatment) post
estimates store s2


logit  vote_may  treatment female age low_education high_educat i.employmentstatus 
margins, dydx(   treatment) post
estimates store s3



logit   vote_nov  treatment female age low_education high_educat i.employmentstatus 
margins, dydx(   treatment) post
estimates store s4


coefplot (s1 , label( "Turnout 2016 (Placebo)")) ( s2, label( "Turnout April 2019")) ///
 ( s3, label( "Turnout May 2019 (Short-term effect)")) ( s4, label("Turnout November 2019 (Long-term effect)")) ///
 , keep ( treatment) vertical yline(0) ylabel(-0.04(.04).2) xlabel("")  title ("Models with covariates") legend(position(6))  ytitle("ATE") level(95)


  graph copy g2

   graph combine g1 g2 ,  title("ATEs: Electoral Officers")
  graph drop g1 g2
 
 
 
 
***************************
*2 DIFF-IN-DIFF
***************************


use "Data_Officers_replication.dta", clear

reg vote_2016 treatment

coefplot , vertical yline(0) keep(treatment) xlabel (1 "June 2016") ytitle ("Treatment Effect") title ("Pre-Treatment Effect (2016)") ylabel (-.05(.025).125)

graph copy g1

 **As a Panel
 gen vote_1=vote_2016
 gen vote_2=vote_april
 gen vote_3=vote_may
 gen vote_4=vote_nov
 
 gen treatment_1=treatment
 gen treatment_2=treatment
 gen treatment_3=treatment
 gen treatment_4=treatment
 
 gen region_1=region
 gen region_2=region
 gen region_3=region
 gen region_4=region
 
 gen female_1=female
 gen female_2=female
 gen female_3=female
 gen female_4=female
 
 gen education_1= education
 gen education_2= education 
 gen education_3= education 
 gen education_4= education 
 
 gen  employmentstatus_1= employmentstatus
 gen  employmentstatus_2= employmentstatus
 gen  employmentstatus_3= employmentstatus
 gen  employmentstatus_4= employmentstatus

 gen age_1= age
 gen age_2= age
 gen age_3= age
 gen age_4= age
 
 gen highincome_1= income_high
 gen highincome_2= income_high
 gen highincome_3= income_high
 gen highincome_4= income_high
 
 gen medincome_1= income_med
 gen medincome_2= income_med
 gen medincome_3= income_med
 gen medincome_4= income_med

  
 gen low_education_1=  low_education
 gen low_education_2=  low_education 
 gen low_education_3=  low_education 
 gen low_education_4=  low_education 
 
  
 gen high_education_1=  high_education
 gen high_education_2=  high_education 
 gen high_education_3=  high_education 
 gen high_education_4=  high_education 
 
 
 encode codpanelista, generate(panelista_num)
 
 
 keep employmentstatus_* highincome_* medincome_*  education_* female_* age_* region_1 region_2 region_3 region_4 codpanelista panelista_num vote_1 vote_2 vote_3 vote_4 treatment_*  low_education_* high_education_*
 
 reshape long vote_ treatment_ region_ employmentstatus_ education_ female_ age_  highincome_ medincome_  high_education_ low_education_, i(codpanelista) j(wave)
   
xtset panelista_num wave

tab wave, gen(ww)
gen int2=treatment_*ww2
gen int3=treatment_*ww3
gen int4=treatment_*ww4

xtreg vote_ treatment_ i.wave int2 int3 int4 age_ female_ low_education_ high_education_   i.employmentstatus_ 
coefplot, keep(int2 int3 int4) vertical yline(0)  xlabel(1 "April 2019" 2 "May 2019" 3 "November 2019") title ("Diff-in-Diff Estimation") ytitle ("Treatment Effect") ylabel (-.05(.025).125) level(95)
graph copy g2
graph combine g1 g2
graph drop  g1 g2



*********************
* 3. ATTITUDES
*********************

use "Data_Officers_replication.dta" , clear

***************************
*Create change variables
***************************

replace voteimp_w1=.  if  voteimp_w1 ==99
replace voteimp_w2=.  if  voteimp_w2 ==99
replace voteimp_w3=.  if  voteimp_w3 ==99

gen d_voteimp_may=voteimp_w2-voteimp_w1
gen d_voteimp_nov=voteimp_w3-voteimp_w1

replace voteduty_w1=. if voteduty_w1 ==99
replace voteduty_w2=. if voteduty_w2 ==99
replace voteduty_w3=. if voteduty_w3 ==99

gen d_voteduty_may=voteduty_w2-voteduty_w1
gen d_voteduty_nov=voteduty_w3-voteduty_w1

replace cleanelections_w1=.  if  cleanelections_w1==99
replace cleanelections_w2=.  if  cleanelections_w2==99
replace cleanelections_w3=.  if  cleanelections_w3==99

gen d_cleanelections_may=cleanelections_w2-cleanelections_w1
gen d_cleanelections_nov=cleanelections_w3-cleanelections_w1

replace trustparties_w1=. if  trustparties_w1==99
replace trustparties_w2=. if  trustparties_w2==99
replace trustparties_w3=. if  trustparties_w3==99

gen d_trustparties_may=trustparties_w2-trustparties_w1
gen d_trustparties_nov=trustparties_w3-trustparties_w1

replace  freedomideas_w1=. if freedomideas_w1==99
replace  freedomideas_w2=. if freedomideas_w2==99
replace  freedomideas_w3=. if freedomideas_w3==99

gen d_freedomideas_may=freedomideas_w2-freedomideas_w1
gen d_freedomideas_nov=freedomideas_w3-freedomideas_w1

replace citizensimp_w1=. if citizensimp_w1==99
replace citizensimp_w2=. if citizensimp_w2==99
replace citizensimp_w3=. if citizensimp_w3==99

gen d_citizensimp_may=citizensimp_w2-citizensimp_w1
gen d_citizensimp_nov=citizensimp_w3-citizensimp_w1

replace votenotimp_w1=. if votenotimp_w1==99
replace votenotimp_w2=. if votenotimp_w2==99
replace votenotimp_w3=. if votenotimp_w3==99

gen d_votenotimp_may=votenotimp_w2-votenotimp_w1
gen d_votenotimp_nov=votenotimp_w3-votenotimp_w1

replace corruption_w1=. if   corruption_w1==99
replace corruption_w2=. if    corruption_w2==99
replace corruption_w3=. if    corruption_w3==99

gen d_corruption_may= corruption_w2-corruption_w1
gen d_corruption_nov= corruption_w3-corruption_w1

replace dontunderstandpolitics_w1=. if   dontunderstandpolitics_w1==99
replace dontunderstandpolitics_w2=. if    dontunderstandpolitics_w2==99
replace dontunderstandpolitics_w3=. if    dontunderstandpolitics_w3==99

gen d_dontunderstandpolitics_may=dontunderstandpolitics_w2-dontunderstandpolitics_w1
gen d_dontunderstandpolitics_nov=dontunderstandpolitics_w3-dontunderstandpolitics_w1

replace demonotworking_w1=. if   demonotworking_w1==99
replace demonotworking_w2=. if    demonotworking_w2==99
replace demonotworking_w3=. if    demonotworking_w3==99

gen d_demonotworking_may=demonotworking_w2-demonotworking_w1
gen d_demonotworking_nov=demonotworking_w3-demonotworking_w1

replace systnotworried_w1=. if    systnotworried_w1==99
replace systnotworried_w2=. if    systnotworried_w2==99
replace systnotworried_w3=. if    systnotworried_w3==99

gen d_systnotworried_may=systnotworried_w2-systnotworried_w1
gen d_systnotworried_nov=systnotworried_w3-systnotworried_w1



reg d_voteimp_may  voteimp_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus 
estimates store A
reg  d_citizensimp_may citizensimp_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store B
reg  d_cleanelections_may  cleanelections_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store C
reg  d_trustparties_may trustparties_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store D
reg   d_votenotimp_may  votenotimp_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store E
reg  d_voteduty_may  voteduty_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store F
coefplot  A, bylabel(Voting is important)  subtitle(, size(small)) || B , bylabel(Citizens are important in Spanish politics) || C , bylabel(Elections are not fraudulent) /// 
|| E, bylabel(Voting does not change anything)  ||  D, bylabel(Trust in political parties)  ||  F,  bylabel(Voting is a duty) || ///
, keep( treatment) xline(0) ylabe(1 "ATE") level(95)


reg   d_freedomideas_may   freedomideas_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store G
reg  d_corruption_may corruption_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store H
reg  d_dontunderstandpolitics_may dontunderstandpolitics_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store I
reg  d_demonotworking_may demonotworking_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store J
reg  d_systnotworried_may systnotworried_w1 vote_2016 treatment  female age low_education high_educat i.employmentstatus    , 
estimates store K
coefplot  G, bylabel(All ideas should be freely expressed) subtitle(, size(small)) || H, bylabel(Corruption is pervasive) || I, bylabel(I don't understand most political issues) || ///
 J, bylabel(Democracy is not working well)  || K, bylabel(Political system does not care) ||  ///
, keep( treatment) xline(0) ylabe(1 "ATE") level(95)




log close
